home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Produtividade / OpenOffice.org 2.0.1 / openofficeorg4.cab / test_calendar.py < prev    next >
Text File  |  2005-11-19  |  2KB  |  62 lines

  1. import calendar
  2. import unittest
  3.  
  4. from test import test_support
  5.  
  6.  
  7. class CalendarTestCase(unittest.TestCase):
  8.     def test_isleap(self):
  9.         # Make sure that the return is right for a few years, and
  10.         # ensure that the return values are 1 or 0, not just true or
  11.         # false (see SF bug #485794).  Specific additional tests may
  12.         # be appropriate; this tests a single "cycle".
  13.         self.assertEqual(calendar.isleap(2000), 1)
  14.         self.assertEqual(calendar.isleap(2001), 0)
  15.         self.assertEqual(calendar.isleap(2002), 0)
  16.         self.assertEqual(calendar.isleap(2003), 0)
  17.  
  18.     def test_setfirstweekday(self):
  19.         self.assertRaises(ValueError, calendar.setfirstweekday, 'flabber')
  20.         self.assertRaises(ValueError, calendar.setfirstweekday, -1)
  21.         self.assertRaises(ValueError, calendar.setfirstweekday, 200)
  22.         orig = calendar.firstweekday()
  23.         calendar.setfirstweekday(calendar.SUNDAY)
  24.         self.assertEqual(calendar.firstweekday(), calendar.SUNDAY)
  25.         calendar.setfirstweekday(calendar.MONDAY)
  26.         self.assertEqual(calendar.firstweekday(), calendar.MONDAY)
  27.         calendar.setfirstweekday(orig)
  28.  
  29.     def test_enumerateweekdays(self):
  30.         self.assertRaises(IndexError, calendar.day_abbr.__getitem__, -10)
  31.         self.assertRaises(IndexError, calendar.day_name.__getitem__, 10)
  32.         self.assertEqual(len([d for d in calendar.day_abbr]), 7)
  33.  
  34.     def test_days(self):
  35.         for attr in "day_name", "day_abbr":
  36.             value = getattr(calendar, attr)
  37.             self.assertEqual(len(value), 7)
  38.             self.assertEqual(len(value[:]), 7)
  39.             # ensure they're all unique
  40.             d = {}
  41.             for v in value:
  42.                 d[v] = 1
  43.             self.assertEqual(len(d), 7)
  44.  
  45.     def test_months(self):
  46.         for attr in "month_name", "month_abbr":
  47.             value = getattr(calendar, attr)
  48.             self.assertEqual(len(value), 13)
  49.             self.assertEqual(len(value[:]), 13)
  50.             self.assertEqual(value[0], "")
  51.             # ensure they're all unique
  52.             d = {}
  53.             for v in value:
  54.                 d[v] = 1
  55.             self.assertEqual(len(d), 13)
  56.  
  57. def test_main():
  58.     test_support.run_unittest(CalendarTestCase)
  59.  
  60. if __name__ == "__main__":
  61.     test_main()
  62.